import os
path = os.getcwd()+"\\script3"
dirs = os.listdir(path)
for dir in dirs:
    print(dir)
    list = []
    f1 = open(path+"\\"+dir,"r",encoding='GBK')
    text_lines = f1.readlines()
    for line in text_lines:
        if "npc" in line:
            str1 = line[line.rfind("id\":\"")+5:]
            str2 = str1[0:str1.rfind("\",\"\":\"npc")]
            list.append(str2)
            continue
        elif "text" in line:
            str1 = line[line.rfind("text\":\"")+7:]
            str2 = str1[0:str1.rfind("\"}")]
            list.append(str2)
            continue
    f1.close()
    with open(path+"\\0"+dir,"w") as f2:
        for ScriptText in list:
            f2.write(ScriptText+"\r\n")